
# ifndef __DFX_RENDER_DATA_H__
# define __DFX_RENDER_DATA_H__

# include "dfxCore.h"
# include "dfxVertexFormat.h"

namespace DFX
{
    class GraphicsDevice;

    enum BUFFER_USAGE
    {
        BUFFER_USAGE_STATIC,
        BUFFER_USAGE_DYNAMIC,
        BUFFER_USAGE_MAX
    };

    enum MAP_FLAGS
    {
        MAP_FLAGS_READ   = 0x1,
        MAP_FLAGS_WRITE  = 0x2
    };

    enum PRIMITIVE_TYPE
    {
        PRIMITIVE_TYPE_POINT_LIST,
        PRIMITIVE_TYPE_LINE_LIST,
        PRIMITIVE_TYPE_LINE_STRIP,
        PRIMITIVE_TYPE_TRIANGLE_LIST,
        PRIMITIVE_TYPE_TRIANGLE_STRIP,
        PRIMITIVE_TYPE_TRIANGLE_FAN,
        PRIMITIVE_TYPE_MAX
    };

    class DFX_EXPORT RenderData
    {
    protected:

        String              mName;
        BUFFER_USAGE        mVBUsage;
        BUFFER_USAGE        mIBUsage;
        UInt32              mNumVertices;
        UInt32              mNumIndices;
        UInt32              mVertexSize;
        UInt32              mIndexSize;
        GraphicsDevice     *mGraphicsDevice;

    public:

        RenderData(GraphicsDevice *gd, const String &name)
            : mGraphicsDevice(gd),
            mName(name),
            mNumIndices(0),
            mNumVertices(0),
            mVertexSize(0),
            mIndexSize(0)
        {
        }

        virtual ~RenderData()
        {
        }

        const String& GetName() const
        {
            return mName;
        }

        GraphicsDevice* GetGraphicsDevice() const
        {
            return mGraphicsDevice;
        }

        BUFFER_USAGE GetVBUsage() const
        {
            return mVBUsage;
        }

        BUFFER_USAGE GetIBUsage() const
        {
            return mIBUsage;
        }

        UInt32 GetNumVertices() const
        {
            return mNumVertices;
        }

        UInt32 GetNumIndices() const
        {
            return mNumIndices;
        }

        UInt32 GetVertexSize() const
        {
            return mVertexSize;
        }

        UInt32 GetIndexSize() const
        {
            return mIndexSize;
        }

        virtual DFXRESULT CreateVertexBuffer(BUFFER_USAGE vbUsage, VertexFormat *format, 
            UInt32 numVertices, void *initialData = NULL) = 0;

        virtual DFXRESULT CreateIndexBuffer(BUFFER_USAGE ibUsage, UInt32 indexSize, 
            UInt32 numIndices, void *initialData = NULL) = 0;

        virtual bool HasIndices() = 0;

        virtual DFXRESULT MapVertexBuffer(void **buffer, UInt32 mapFlags) = 0;
        virtual DFXRESULT UnmapVertexBuffer() = 0;

        virtual DFXRESULT MapIndexBuffer(void **buffer, UInt32 mapFlags) = 0;
        virtual DFXRESULT UnmapIndexBuffer() = 0;

        virtual void Activate() = 0;

        virtual void Draw(PRIMITIVE_TYPE type) = 0;
        virtual void Draw(PRIMITIVE_TYPE mode, UInt32 start, UInt32 end, UInt32 count) = 0;
    };

    typedef std::vector<RenderData*>    RenderDataArray;
    typedef RenderDataArray::iterator   RenderDataIterator;
}

# endif